#!/usr/bin/env perl -w
# Time-stamp: <20 Aug 01 17:07:07 giron1>

=head1 NAME

netgen.perl - generates networks

=head1 SYNOPSIS

netgen.perl [commands] [options] I<vocabulary>

see also:

L<"COMMANDS">,
L<"OPTIONS">

=head1 DESCRIPTION

netgen.perl generates a network for vrecog using the original
I<vocabulary> filename and write the results to stdout

=head1 SEE ALSO

The following packages descriptions:

L<STC_DEF|STC_DEF_HTML/STC_DEF>,
L<SIDL_VOCAB|SIDL_VOCAB_HTML/SIDL_VOCAB>

=head1 AUTHOR

 $Id: netgen.perl,v 1.1 2007/10/08 09:26:02 schweitz Exp $
 Franck Giron

=head1 LOG

 $Log: netgen.perl,v $
 Revision 1.1  2007/10/08 09:26:02  schweitz
 version 2.4, lib vergessen

 Revision /main/8  22-Jan-2003.09:54:20  giron1
 Changing header to /usr/bin/env perl.
 
 Revision /main/7  20-Aug-2001.17:22:23  giron1
 updating links
 
 Revision 1.6  2000/04/26 08:37:34  giron1
 Pod documentation updated


=cut

#----------------------------------------------------------------------
# perl packages
#----------------------------------------------------------------------

use Misc;
use SIDL_VOCAB;
use OPTIONS;
use STC_DEF;

#----------------------------------------------------------------------
# MAIN
#----------------------------------------------------------------------
my $STC_Vocab_files =  givehash STC_DEF;

# Define the set of options

my $OptList = new OPTIONS;

$OptList->debug(Do => 0, Usage => 'debuging mode');
$OptList->uscore(Do => 0, Usage => 'put underscore instead of spaces');

# Command processing

$OptList->GetOpt || die "Check your options\n";

my $numargs = @ARGV;
my $usage = !$numargs || ("$ARGV[0]" eq '-h');

if ($usage) {
  $OptList->Usage('vocabulary');
}

# Extract path and keyword information if any from the rest of
# the argument line

my $path = '';
my $keyw = $ARGV[0];

if ($ARGV[0] =~ m/([^\/]+)$/) {
  $path = $`;
  $keyw = $1;
}

$OptList->{debug}{Do} && warn "keyw=$keyw, path=$path\n";

# Determines vocabulary file from keyword
if (exists($STC_Vocab_files->{$keyw}) ) {
  $voc_file = $path . $STC_Vocab_files->{$keyw};
} else {
  $voc_file = $path . $keyw;
}

$OptList->{debug}{Do} && warn "vocfile=$voc_file\n";

# Process each words

open FILEWORDS, "<$voc_file" || die "cannot read file: $voc_file";

# write enter node
print "(!ENTER{_SIL_}(\n";

# Expand each entry

while (<FILEWORDS>) {
    chop;

    # replaces all punctuation characters with space
    s/[_\-?,;.!:]/ /g;

    # suppresses final spaces
    s/\s+$//g;

    # replaces many spaces with a single one
    s/\s{2,}/ /g;

    # replaces iso accented characters with esc codes
    $_ = iso_to_esc('\\\\',$_);

    if ($OptList->{uscore}{Do}) {
      # replaces spaces with underscore
      s/\s/_/g;
    }
    else {
      # replaces spaces with \n
      s/\s/\n/g;
    }

    # prints the output if not empty

    print "$_\n|\n" unless ( m/^\s*$/);
}
close FILEWORDS;

# Write end node

print "_SIL_\n",
      "){_SIL_}!EXIT)\n";

exit;


__END__

=head1 COMMANDS

The following commands are defined:

=over 10

=item -debug	

 debuging mode

=item -uscore	

 put underscore instead of spaces

=back

=head1 OPTIONS

No options up to now.

=cut
